package com.aote.filter;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.browsesoft.Entity;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.oa.LookFilter;
import com.browsesoft.user.User;

public class FindParentComponentEntity implements LookFilter {
	/**
	 * 把得到的实体通过parentid给过滤掉
	 */
	public List filter(User user, HTMLBasicComponent component, List infors,
			HttpServletRequest request) {
		List result = new LinkedList();
		// 得到父组件对应实体的id
		HTMLBasicComponent com = component.getParent();
		Entity entity = (Entity) com.getModel();
		String id = entity.getID();
		Iterator iter = infors.iterator();
		while (iter.hasNext()) {
			Entity ent = (Entity) iter.next();
			String parentid = (String) ent.getAttributes().get("parentid");
			if (id.equals(parentid)) {
				result.add(ent);
			}
		}

		return result;
	}
}
